function findCourier(doc) {
    doc.$res.hide();

    let timeout;
    let findingPhone;
    json.waitingForSamePhone = false;// 提交同一内容须等待 10 秒
    let findByPhone = function () {
        doc.$iptPhone.val(doc.$iptPhone.val().trim());
        if (!test_ipt(testPhone, doc.$iptPhone, doc.$labelFind)) {
            layer.msg('请输入正确的手机号码');
            doc.$iptPhone.focus();
            return false;
        }
        if (timeout !== undefined) clearTimeout(timeout);
        timeout = setTimeout(function () {
            json.waitingForSamePhone = false;
        }, 10000);
        if (findingPhone === doc.$iptPhone.val() && json.waitingForSamePhone) {
            layer.msg('请勿重复提交同一内容');
            return false;
        }
        findingPhone = doc.$iptPhone.val();
        let windowId = layer.load();
        $.getJSON("/admin/views/courier/find.do", {
            phone: doc.$iptPhone.val()
        }, function (data) {
            layer.close(windowId);
            layer.msg(data.message);
            if (data.status === 0) {
                json = data.data;
                reset(doc);
                doc.$res.fadeIn(1000);
            } else if (data.status === -404) {
                location.assign('/login.html');
            }
            json.waitingForSamePhone = true;
        });
        return false;
    };

    let keyPressEvent = function (key) {
        if (key.key === 'Enter') {
            findByPhone();
            onkeypress = undefined;
        }
    };

    doc.$iptPhone.bind('input propertychange', function () {
        test_ipt(testPhone, doc.$iptPhone, doc.$labelFind);
        onkeypress = keyPressEvent;
    });

    doc.$find.click(findByPhone);
}

function reset(doc) {
    doc.$name.val(json.name);
    doc.$passwd.val(json.passwd);
    doc.$email.val(json.email);
    doc.$phone.val(json.phone);
    doc.$idNumber.val(json.idNumber);
    doc.$dispatches.val(json.dispatches);
    doc.$regtime.val(json.regtime);
    doc.$logintime.val(json.logintime);
    doc.$addr.val(json.addr);
    doc.$status_0 !== null ?
        json.status === '正常' ? doc.$status_0.prop('checked', true) : doc.$status_2.prop('checked', true) :
        doc.$status.val(json.status);
    if (doc.$labelName !== null) {
        test_ipt(testRealName, doc.$name, doc.$labelName);
        test_ipt(testPasswd, doc.$passwd, doc.$labelPasswd);
        test_ipt(testEmail, doc.$email, doc.$labelEmail);
        test_ipt(testPhone, doc.$phone, doc.$labelPhone);
        test_ipt(testIdNumber, doc.$idNumber, doc.$labelIdNumber);
        test_ipt(testDispatches, doc.$dispatches, doc.$labelDisp);
    }
    doc.$passwd.prop('type', 'password');
}